package com.ruoyi.waterDistribution.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.business.waterDistribution.WiCropB;
import com.ruoyi.waterDistribution.service.IWiCropBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 基本作物类型Controller
 * 
 * @author ps
 * @date 2023-02-16
 */
@RestController
@RequestMapping("/WiCropB")
public class WiCropBController extends BaseController
{
    @Autowired
    private IWiCropBService wiCropBService;

    /**
     * 查询基本作物类型列表
     */
    @RequiresPermissions("waterDistribution:WiCropB:list")
    @GetMapping("/list")
    public TableDataInfo list(WiCropB wiCropB)
    {
        startPage();
        List<WiCropB> list = wiCropBService.selectWiCropBList(wiCropB);
        return getDataTable(list);
    }

    /**
     * 导出基本作物类型列表
     */
    @RequiresPermissions("waterDistribution:WiCropB:export")
    @Log(title = "基本作物类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WiCropB wiCropB)
    {
        List<WiCropB> list = wiCropBService.selectWiCropBList(wiCropB);
        ExcelUtil<WiCropB> util = new ExcelUtil<WiCropB>(WiCropB.class);
        util.exportExcel(response, list, "基本作物类型数据");
    }

    /**
     * 获取基本作物类型详细信息
     */
    @RequiresPermissions("waterDistribution:WiCropB:query")
    @GetMapping(value = "/{cropCd}")
    public AjaxResult getInfo(@PathVariable("cropCd") String cropCd)
    {
        return success(wiCropBService.selectWiCropBByCropCd(cropCd));
    }

    /**
     * 新增基本作物类型
     */
    @RequiresPermissions("waterDistribution:WiCropB:add")
    @Log(title = "基本作物类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WiCropB wiCropB)
    {
        return toAjax(wiCropBService.insertWiCropB(wiCropB));
    }

    /**
     * 修改基本作物类型
     */
    @RequiresPermissions("waterDistribution:WiCropB:edit")
    @Log(title = "基本作物类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WiCropB wiCropB)
    {
        return toAjax(wiCropBService.updateWiCropB(wiCropB));
    }

    /**
     * 删除基本作物类型
     */
    @RequiresPermissions("waterDistribution:WiCropB:remove")
    @Log(title = "基本作物类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{cropCds}")
    public AjaxResult remove(@PathVariable String[] cropCds)
    {
        return toAjax(wiCropBService.deleteWiCropBByCropCds(cropCds));
    }
}
